//
//  MiaoSha_TCell.swift
//  MikerShop
//
//  Created by eme on 2017/2/20.
//  Copyright © 2017年 eme. All rights reserved.
//

/*
 owner:cy
 update:2017年02月20日10:31:53
 秒杀cell
 */
import UIKit
import RxSwift
import RickonCore
import BrandonCore


class MiaoSha_TCell: UITableViewCell {
    
    //商品名称
    @IBOutlet weak var pdname_Lb: UILabel!
    //店铺进货价
    @IBOutlet weak var shprice_Lb: UILabel!
    @IBOutlet weak var shprice_V: UIView!
    
    @IBOutlet weak var jinPriceImg_V: UIImageView!
    //  利润
    @IBOutlet weak var profit_V: UIView!
    @IBOutlet weak var profit_Lb: UILabel!
    
    ///选择表示 selected:马上抢 normal:去看看
    @IBOutlet weak var state_btn: UIButton!
    @IBOutlet weak var stock_desc_Lb: UILabel!
    
    @IBOutlet weak var sellout_ImgV: UIImageView!
    @IBOutlet weak var img1_ImgV: UIImageView!
    
    @IBOutlet weak var seperateLine_V: UIView!
    private let disposeBag = DisposeBag()
    var tap_Block:((Void) -> Void)?
    var item :HpProductModel?{
        didSet{
            if let item = self.item {
                self.pdname_Lb.text = item.pdname
                self.img1_ImgV.setUrlImage(item.img1)
                self.profit_Lb.text = "利:\(item.profit.getFormatStr())"
                self.jinPriceImg_V.image = UIImage(named: AppData.getPriceImgName(), in: RobbCore.bundle, compatibleWith: nil)
                self.shprice_Lb.text = AppData.getFinalShowPrice(jinPrice: item.shprice, lingPrice: item.bdprice).getPriceStr()
                
                if item.stock == 0 || item.pdstate != "3" {
                    self.sellout_ImgV.isHidden = false
                    self.sellout_ImgV.image = UIImage(named: item.stock == 0 ?"sellout":"failure", in: RobbCore.bundle, compatibleWith: nil)
                }else{
                    self.sellout_ImgV.isHidden = true
                }
                if  case .audited = AppData.appState {
                    self.profit_V.isHidden = false
                    /// 1 表示商品 0 表示是仪器等非商品类型
                    self.profit_V.isHidden = item.ptisproduct != "1"
                }else{
                    self.profit_V.isHidden = true
                }
                self.stock_desc_Lb.text = "限量\(item.stock)\(item.pdunit)"
            }
        }
    }
    
    
    override func awakeFromNib() {
        self.profit_V.changeBorderColor(Theme.v.product_li,cornerRadius: 1)
        self.seperateLine_V.backgroundColor = Theme.v.separate_Line
        self.state_btn.changeBorderColor(UIColor.clear)
        self.state_btn.backgroundColor = UIColor.clear
        self.state_btn.setBackgroundImage(UIColor(hex: "fd6863").getImage(), for: .normal)
        self.state_btn.setBackgroundImage(UIColor(hex: "e31436").getImage(), for: .selected)
        self.pdname_Lb.normal_fontSize(14)
        self.shprice_Lb.bold_fontSize(14)
        self.stock_desc_Lb.normal_fontSize(13)
        self.profit_Lb.normal_fontSize(11)
        self.state_btn
            .rx.tap
            .subscribe(onNext: { [unowned self] ( _ ) in
                self.tap_Block?()
            })
            .disposed(by: disposeBag)
    }
}


